<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="工厂:" prop="tmBasPlantId">
          <el-select v-model="formModel.plantNo" clearable filterable>
            <el-option v-for="item in plantOptions" :key="item.tmBasPlantId" :label="item.plantNameC" :value="item.plantNo"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="计划类型:" prop="planType">
          <hey-select v-model="formModel.planType" clcd="plan_type_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('need_plan_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('need_plan_add')" plain @click="handleAdd">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :table-data="tableData"  :columns="columns">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="80"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span class="hey_tools_btn" v-if="hasPermission('need_plan_edit')" @click="handleEdit(row)">编辑</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="批次计划信息"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <need-plan-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

  </div>
</template>

<script>

  export default {
    name: 'NeedPlanList',
    components: {
      NeedPlanMnt: () => import('./need-plan-mnt')
    },
    props: {},
    data() {
      return {
        dialogVisible: false,
        operType: '',
        editData:{},
        tableData:[],
        plantOptions:[],
        formModel: {
          plantNo: '',
          planType: '',
          isDelete: '0'
        },
        columns: [
          { title: '计划类型', key: 'planType',clcd:'plan_type_cd'},
          { title: '工厂代码', key: 'plantNo'},
          { title: '工厂名称', key: 'plantNameC'},
          { title: '车间代码', key: 'workshopNo'},
          { title: '车间名称', key: 'workshopNameC'},
          { title: '交付工位', key: 'ulocNo'},
          { title: '工位名称', key: 'ulocName'},
          { title: '计划数量', key: 'qty'},
          { title: '计划年份', key: 'planYear'},
          { title: '计划月份', key: 'planMonth'},
          { title: '计划日', key: 'planDay'},
          { title: '创建时间', key: 'createTime' },
          { title: '创建人', key: 'createUsername' },
          { title: '更新次数', key: 'updateNum'},
          { title: '最后修改时间', key: 'lastUpdateTime'},
          { title: '最后修改人', key: 'lastUpdateUsername' },
        ]
      }
    },
    computed: {

    },
    mounted() {
      this.getPlants()
    },
    methods: {
      getPlants(){
        const param = {pageNum:1,pageSize:9999}
        param.isDelete = '0'
        param.status = '1'
        this.get('/tmBasPlant/queryTmBasPlant', param).then(res => {
          this.plantOptions = res.list
        })
      },
      queryList() {
        this.$refs.table.query('/teOfmProPlan/queryTeOfmProPlan', this.formModel, '', false)
      },
      handleAdd() {
        this.operType = 'add'
        this.dialogVisible = true
      },
      handleEdit(row) {
        this.operType = 'edit'
        this.editData = row || {}
        if(row.planType == '02'){
          //月计划
          this.editData.month = row.planYear + '-' + row.planMonth
        }
        if(row.planType == '03'){
          //日计划
          this.editData.planDate = row.planYear + '-' + row.planMonth + '-' + row.planDay
        }
        this.dialogVisible = true
      },
    }
  }
</script>


